package com.x298017064010.hellowweex;

import android.app.Application;
import android.content.Intent;

import com.taobao.weex.InitConfig;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.appfram.navigator.IActivityNavBarSetter;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by x298017064010 on 17/4/7.
 */
public class WeexApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        InitConfig config = new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build();
        WXSDKEngine.initialize(this, config);


        WXSDKEngine.setActivityNavBarSetter(new IActivityNavBarSetter() {
            @Override
            public boolean push(String param) {
                try {
                    JSONObject jsonObject = new JSONObject(param);
                    String url = jsonObject.getString("url");
                    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("path", url);
                    startActivity(intent);

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return true;
            }

            @Override
            public boolean pop(String param) {
                return false;
            }

            @Override
            public boolean setNavBarRightItem(String param) {
                return false;
            }

            @Override
            public boolean clearNavBarRightItem(String param) {
                return false;
            }

            @Override
            public boolean setNavBarLeftItem(String param) {
                return false;
            }

            @Override
            public boolean clearNavBarLeftItem(String param) {
                return false;
            }

            @Override
            public boolean setNavBarMoreItem(String param) {
                return false;
            }

            @Override
            public boolean clearNavBarMoreItem(String param) {
                return false;
            }

            @Override
            public boolean setNavBarTitle(String param) {
                return false;
            }
        });
    }


}
